#ifndef JAE_OBJECTTERRAIN_H_
#define JAE_OBJECTTERRAIN_H_

#include "object.h"

/*
 * This file base on the great tutorial of "www.videotutorialsrock.com"
 */

/****************************************************//**
 * Project-Namespace
 ********************************************************/
namespace jae
{

/****************************************************//**
 * This class gereates a Terrain out of an heightmap!
 ********************************************************/
class ObjectTerrain : public Object
{
public:

    ObjectTerrain();
    virtual ~ObjectTerrain();

    virtual void setScaleFactor(GLfloat aValue);
    virtual GLfloat getScaleFactor();
    
    void createTerrain(const char* aFileName);
    void setMaxHeight(float aValue);
    float getMaxHeight();
    bool parseTerrainFile(const char* aFilename);
    void createColormap(const char* aFileName);
protected:
    virtual void renderModel();
private:
    void renderTerrain();
    bool getNextParam(std::string* aLine, std::string* aNextParam);
    void checkLineSyntax(const char* aFilename, int lineNumber, 
            std::string& aCommand, int aParamCount, int aExpectedCount);
    
    void calcNormals();
    bool _terrainCreated, _textureLoaded;
    bool _tiling;
    GLuint _textureIndex; //"-1" = disable, no texture
    int _width;
    int _length;
    float _maxHeight;
    float** _heights;
    Vector3D** _normals;
};
} //jae Namespace

#endif /*JAE_OBJECTTERRAIN_H_*/
